package com.zxx.coolweather._wuguan3_ok;

import android.app.Activity;
import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author zxx on 2022/1/13
 */
public class FileUtils {

    public static final String BASE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/";
    /** 临时目录*/
    //public static final String BASE_TEMP_PATH = BASE_PATH + "/temp";

    private Activity activity;

    public FileUtils(Activity context) {
        activity = context;
    }


    public static File writeBytesToFile(InputStream is,String name) {
        File file = new File(BASE_PATH + name);    //savepath
        FileOutputStream fos = null;
        try {
            byte[] data = new byte[2048];
            int read = 0;
            fos = new FileOutputStream(file);

            while ((read = is.read(data)) > -1) {
                fos.write(data, 0, read);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return file;
    }

}
